using UnityEngine;
using System.Collections;

public class Player_Attack_State : State {
	
	public override void Enter_State(Alive_object _player_script)
	{
//		_player_script.animation["attack"].speed = ((Player)_player_script).player_data_.Player_Attack_Speed;
		
		_player_script.animation.AddClip(_player_script.animation["attack"].clip,"attack_upper");
		_player_script.animation["attack_upper"].AddMixingTransform(_player_script.Necks);
		_player_script.animation["attack_upper"].layer = 10;
//		_player_script.animation["attack_upper"].speed = ((Player)_player_script).player_data_.Player_Attack_Speed;
				
		if(((Player)_player_script).Player_Direction.Equals(Vector3.zero))
		{
			_player_script.animation.Play("attack");
		}
		else
		{
			_player_script.animation.Play("run");
			_player_script.animation.Play("attack_upper");
		}
	}
	public override void Excute_State(Alive_object _player_script)
	{	
		if( animation.IsPlaying("attack").Equals(false) && animation.IsPlaying("attack_upper").Equals(false) )
		{
			CollisionManager.getInstance().Request_Attack(((Player)_player_script).player_data_.Player_Attack_Damage);
			_player_script.fsm.Change_state(_player_script.arr_state_[0],_player_script);
		}
		if( ((Player)_player_script).Player_Direction.Equals(Vector3.zero) == false )
		{
			_player_script.transform.position += ((Player)_player_script).Player_Direction * _player_script.player_data_.Player_Movement_Speed * Time.deltaTime;
			_player_script.transform.LookAt( _player_script.transform.position + ((Player)_player_script).Player_Direction );
			float distance = Vector3.Distance(_player_script.transform.position,Vector3.zero);
			if( 2.0f >= distance + 0.5f )
			{
				Camera.mainCamera.orthographicSize = 2.0f;
			}
			else
			{
				Camera.mainCamera.orthographicSize = distance + 0.5f;
				if( 12.0f <= Camera.mainCamera.orthographicSize )
				{
					Camera.mainCamera.orthographicSize = 12.0f;
				}
			}
			if(_player_script.animation.IsPlaying("attack_upper").Equals(false)){
				_player_script.animation.Play("run");
				_player_script.animation.Play("attack_upper");
			}
			
		}
		else
		{
			_player_script.animation.Play("attack");
		}
	}
	public override void Exit_State(Alive_object _player_script)
	{
//		animation.Stop();
	}
}